<?php
/**
 * 登录验证，登录cookie
 */

class Login_Raw
{
    public function checkLogin($email, $password)
    {
        $one = new Data_One();
        $where = 'nick="' . mysql_escape_string($email) . '" or email="'.mysql_escape_string($email).'"';
        $res = $one->selectRawWhere('t_user_info', array('*'), $where);
        
        if (empty($res['data']))
        {
        	throw new Exception('login:user not exists');
        }
        
        if ( md5(md5($password).$res['data'][0]['salt']) != $res['data'][0]['password'])
        {
        	throw new Exception('login:password error');
        }

        $uid = $res['data'][0]['uid'];
        $this->setLogin($uid);
        return $uid;
    }

    public function checkCookie()
    {
        $uid = Tool_Input::clean('c', '_uid', 'str');
        return $uid;
    }

    public function setLogin($uid, $remember = false, $account='')
    {
        setcookie('_uid', $uid, time()+86400, '/');
    }

    public function clearCookie()
    {
        setcookie('_uid', '', -86400, '/');
    }

}

?>